    package com.social.model;

    import java.sql.Date;
    import java.util.List;

    /**
     * 用户模型类
     * 扩展支持好友推荐所需的额外属性和功能
     */
    public class User {
        // 基础用户信息
        private int id;
        private String nickname;
        private String phone;
        private String email;
        private String password;
        private String avatar;
        private Date birthdate;
        private String gender;
        private String city;      // 所在城市
        private String school;    // 学校信息
        private String friends;
        // 好友关系相关
        private int friendCount;            // 好友数量
        private int mutualFriendCount;      // 共同好友数量
        private List<Integer> mutualFriendIds; // 共同好友ID列表
        private String recommendReason;     // 推荐理由

        // 在线状态
        private boolean online;             // 是否在线
        private Date lastActiveTime;        // 最后活跃时间


        public String getFriends() {
            return friends;
        }

        public void setFriends(String friends) {
            this.friends = friends;
        }

        // 无参构造方法
        public User() {
        }

        // Getter和Setter方法
        public int getId() {
            return id;
        }

        public void setId(int id) {
            this.id = id;
        }

        public String getNickname() {
            return nickname;
        }

        public void setNickname(String nickname) {
            this.nickname = nickname;
        }

        public String getPhone() {
            return phone;
        }

        public void setPhone(String phone) {
            this.phone = phone;
        }

        public String getEmail() {
            return email;
        }

        public void setEmail(String email) {
            this.email = email;
        }

        public String getPassword() {
            return password;
        }

        public void setPassword(String password) {
            this.password = password;
        }

        public String getAvatar() {
            return avatar;
        }

        public void setAvatar(String avatar) {
            this.avatar = avatar;
        }

        public Date getBirthdate() {
            return birthdate;
        }

        public void setBirthdate(Date birthdate) {
            this.birthdate = birthdate;
        }

        public String getGender() {
            return gender;
        }

        public void setGender(String gender) {
            this.gender = gender;
        }

        public String getCity() {
            return city;
        }

        public void setCity(String city) {
            this.city = city;
        }

        public String getSchool() {
            return school;
        }

        public void setSchool(String school) {
            this.school = school;
        }

        public int getFriendCount() {
            return friendCount;
        }

        public void setFriendCount(int friendCount) {
            this.friendCount = friendCount;
        }

        public int getMutualFriendCount() {
            return mutualFriendCount;
        }

        public void setMutualFriendCount(int mutualFriendCount) {
            this.mutualFriendCount = mutualFriendCount;
        }

        public List<Integer> getMutualFriendIds() {
            return mutualFriendIds;
        }

        public void setMutualFriendIds(List<Integer> mutualFriendIds) {
            this.mutualFriendIds = mutualFriendIds;
            this.mutualFriendCount = mutualFriendIds != null ? mutualFriendIds.size() : 0;
        }

        public String getRecommendReason() {
            return recommendReason;
        }

        public void setRecommendReason(String recommendReason) {
            this.recommendReason = recommendReason;
        }

        public boolean isOnline() {
            return online;
        }

        public void setOnline(boolean online) {
            this.online = online;
        }

        public Date getLastActiveTime() {
            return lastActiveTime;
        }

        public void setLastActiveTime(Date lastActiveTime) {
            this.lastActiveTime = lastActiveTime;
        }

        /**
         * 获取用户的年龄
         * @return 年龄
         */
        public int getAge() {
            if (birthdate == null) {
                return 0;
            }

            java.util.Date currentDate = new java.util.Date();
            java.util.Calendar cal = java.util.Calendar.getInstance();
            cal.setTime(birthdate);

            int birthYear = cal.get(java.util.Calendar.YEAR);
            int birthMonth = cal.get(java.util.Calendar.MONTH);
            int birthDay = cal.get(java.util.Calendar.DAY_OF_MONTH);

            cal.setTime(currentDate);
            int currentYear = cal.get(java.util.Calendar.YEAR);
            int currentMonth = cal.get(java.util.Calendar.MONTH);
            int currentDay = cal.get(java.util.Calendar.DAY_OF_MONTH);

            int age = currentYear - birthYear;

            if (currentMonth < birthMonth ||
                    (currentMonth == birthMonth && currentDay < birthDay)) {
                age--;
            }

            return age;
        }

        /**
         * 检查用户是否是当前用户的共同好友
         * @param userId 当前用户ID
         * @return 是否是共同好友
         */
        public boolean isMutualFriendWith(int userId) {
            return mutualFriendIds != null && mutualFriendIds.contains(userId);
        }

        /**
         * 获取用户的在线状态描述
         * @return 在线状态描述
         */
        public String getOnlineStatusDescription() {
            if (online) {
                return "在线";
            } else if (lastActiveTime != null) {
                // 计算最后活跃时间与当前时间的差值
                long diff = new java.util.Date().getTime() - lastActiveTime.getTime();
                long minutes = diff / (60 * 1000);

                if (minutes < 1) {
                    return "刚刚在线";
                } else if (minutes < 60) {
                    return minutes + "分钟前在线";
                } else if (minutes < 1440) {
                    return (minutes / 60) + "小时前在线";
                } else {
                    return (minutes / 1440) + "天前在线";
                }
            } else {
                return "离线";
            }
        }

        @Override
        public String toString() {
            return "User{" +
                    "id=" + id +
                    ", nickname='" + nickname + '\'' +
                    ", phone='" + phone + '\'' +
                    ", email='" + email + '\'' +
                    ", avatar='" + avatar + '\'' +
                    ", birthdate=" + birthdate +
                    ", gender='" + gender + '\'' +
                    ", city='" + city + '\'' +
                    ", school='" + school + '\'' +
                    ", friendCount=" + friendCount +
                    ", mutualFriendCount=" + mutualFriendCount +
                    ", recommendReason='" + recommendReason + '\'' +
                    ", online=" + online +
                    ", lastActiveTime=" + lastActiveTime +
                    '}';
        }
    }